<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html>
<html lang="en">
<head>
  <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  <title>composition.h 示例文件 | Qt Widgets 5.12.3</title>
  <link rel="stylesheet" type="text/css" href="style/offline-simple.css" />
  <script type="text/javascript">
    document.getElementsByTagName("link").item(0).setAttribute("href", "style/offline.css");
    // loading style sheet breaks anchors that were jumped to before
    // so force jumping to anchor again
    setTimeout(function() {
        var anchor = location.hash;
        // need to jump to different anchor first (e.g. none)
        location.hash = "#";
        setTimeout(function() {
            location.hash = anchor;
        }, 0);
    }, 0);
  </script>
</head>
<body>
<div class="header" id="qtdocheader">
  <div class="main">
    <div class="main-rounded">
      <div class="navigationbar">
        <table><tr>
<td ><a href="../qtdoc/index.html">Qt 5.12</a></td><td ><a href="qtwidgets-index.html">Qt Widgets</a></td><td ><a href="qtwidgets-painting-composition-example.html">Composition Modes</a></td><td >composition.h 示例文件</td></tr></table><table class="buildversion"><tr>
<td id="buildversion" width="100%" align="right"><a href="qtwidgets-index.html">Qt 5.12.3 参考指南</a></td>
        </tr></table>
      </div>
    </div>
<div class="content">
<div class="line">
<div class="content mainContent">
<div class="sidebar"><div class="sidebar-content" id="sidebar-content"></div></div>
<h1 class="title">composition.h 示例文件</h1>
<span class="subtitle">painting/composition/composition.h</span>
<!-- $$$painting/composition/composition.h-description -->
<div class="descr"> <a name="details"></a>
<pre class="cpp">

  <span class="comment">/****************************************************************************
  **
  ** Copyright (C) 2016 The Qt Company Ltd.
  ** Contact: https://www.qt.io/licensing/
  **
  ** This file is part of the demonstration applications of the Qt Toolkit.
  **
  ** $QT_BEGIN_LICENSE:BSD$
  ** Commercial License Usage
  ** Licensees holding valid commercial Qt licenses may use this file in
  ** accordance with the commercial license agreement provided with the
  ** Software or, alternatively, in accordance with the terms contained in
  ** a written agreement between you and The Qt Company. For licensing terms
  ** and conditions see https://www.qt.io/terms-conditions. For further
  ** information use the contact form at https://www.qt.io/contact-us.
  **
  ** BSD License Usage
  ** Alternatively, you may use this file under the terms of the BSD license
  ** as follows:
  **
  ** &quot;Redistribution and use in source and binary forms, with or without
  ** modification, are permitted provided that the following conditions are
  ** met:
  **   * Redistributions of source code must retain the above copyright
  **     notice, this list of conditions and the following disclaimer.
  **   * Redistributions in binary form must reproduce the above copyright
  **     notice, this list of conditions and the following disclaimer in
  **     the documentation and/or other materials provided with the
  **     distribution.
  **   * Neither the name of The Qt Company Ltd nor the names of its
  **     contributors may be used to endorse or promote products derived
  **     from this software without specific prior written permission.
  **
  **
  ** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  ** &quot;AS IS&quot; AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  ** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  ** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
  ** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  ** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  ** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  ** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  ** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  ** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  ** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.&quot;
  **
  ** $QT_END_LICENSE$
  **
  ****************************************************************************/</span>

  <span class="preprocessor">#ifndef COMPOSITION_H</span>
  <span class="preprocessor">#define COMPOSITION_H</span>

  <span class="preprocessor">#include &quot;arthurwidgets.h&quot;</span>

  <span class="preprocessor">#if QT_CONFIG(opengl)</span>
  <span class="preprocessor">#include &quot;fbopaintdevice.h&quot;</span>
  <span class="preprocessor">#include &lt;QOpenGLTextureBlitter&gt;</span>
  <span class="preprocessor">#endif</span>

  <span class="preprocessor">#include &lt;QPainter&gt;</span>
  <span class="preprocessor">#include &lt;QEvent&gt;</span>

  <span class="keyword">class</span> <span class="type"><a href="qpushbutton.html">QPushButton</a></span>;
  <span class="keyword">class</span> <span class="type"><a href="qradiobutton.html">QRadioButton</a></span>;

  <span class="keyword">class</span> CompositionWidget : <span class="keyword">public</span> <span class="type"><a href="qwidget.html">QWidget</a></span>
  {
      Q_OBJECT

  <span class="keyword">public</span>:
      CompositionWidget(<span class="type"><a href="qwidget.html">QWidget</a></span> <span class="operator">*</span>parent);

  <span class="keyword">public</span> <span class="keyword">slots</span>:
  <span class="type">void</span> nextMode();

  <span class="keyword">private</span>:
      bool m_cycle_enabled;

      <span class="type"><a href="qradiobutton.html">QRadioButton</a></span> <span class="operator">*</span>rbClear;
      <span class="type"><a href="qradiobutton.html">QRadioButton</a></span> <span class="operator">*</span>rbSource;
      <span class="type"><a href="qradiobutton.html">QRadioButton</a></span> <span class="operator">*</span>rbDest;
      <span class="type"><a href="qradiobutton.html">QRadioButton</a></span> <span class="operator">*</span>rbSourceOver;
      <span class="type"><a href="qradiobutton.html">QRadioButton</a></span> <span class="operator">*</span>rbDestOver;
      <span class="type"><a href="qradiobutton.html">QRadioButton</a></span> <span class="operator">*</span>rbSourceIn;
      <span class="type"><a href="qradiobutton.html">QRadioButton</a></span> <span class="operator">*</span>rbDestIn;
      <span class="type"><a href="qradiobutton.html">QRadioButton</a></span> <span class="operator">*</span>rbSourceOut;
      <span class="type"><a href="qradiobutton.html">QRadioButton</a></span> <span class="operator">*</span>rbDestOut;
      <span class="type"><a href="qradiobutton.html">QRadioButton</a></span> <span class="operator">*</span>rbSourceAtop;
      <span class="type"><a href="qradiobutton.html">QRadioButton</a></span> <span class="operator">*</span>rbDestAtop;
      <span class="type"><a href="qradiobutton.html">QRadioButton</a></span> <span class="operator">*</span>rbXor;

      <span class="type"><a href="qradiobutton.html">QRadioButton</a></span> <span class="operator">*</span>rbPlus;
      <span class="type"><a href="qradiobutton.html">QRadioButton</a></span> <span class="operator">*</span>rbMultiply;
      <span class="type"><a href="qradiobutton.html">QRadioButton</a></span> <span class="operator">*</span>rbScreen;
      <span class="type"><a href="qradiobutton.html">QRadioButton</a></span> <span class="operator">*</span>rbOverlay;
      <span class="type"><a href="qradiobutton.html">QRadioButton</a></span> <span class="operator">*</span>rbDarken;
      <span class="type"><a href="qradiobutton.html">QRadioButton</a></span> <span class="operator">*</span>rbLighten;
      <span class="type"><a href="qradiobutton.html">QRadioButton</a></span> <span class="operator">*</span>rbColorDodge;
      <span class="type"><a href="qradiobutton.html">QRadioButton</a></span> <span class="operator">*</span>rbColorBurn;
      <span class="type"><a href="qradiobutton.html">QRadioButton</a></span> <span class="operator">*</span>rbHardLight;
      <span class="type"><a href="qradiobutton.html">QRadioButton</a></span> <span class="operator">*</span>rbSoftLight;
      <span class="type"><a href="qradiobutton.html">QRadioButton</a></span> <span class="operator">*</span>rbDifference;
      <span class="type"><a href="qradiobutton.html">QRadioButton</a></span> <span class="operator">*</span>rbExclusion;
  };

  <span class="keyword">class</span> CompositionRenderer : <span class="keyword">public</span> ArthurFrame
  {
      Q_OBJECT

      <span class="keyword">enum</span> ObjectType { NoObject<span class="operator">,</span> Circle<span class="operator">,</span> Rectangle<span class="operator">,</span> Image };

      Q_PROPERTY(<span class="type">int</span> circleColor READ circleColor WRITE setCircleColor)
      Q_PROPERTY(<span class="type">int</span> circleAlpha READ circleAlpha WRITE setCircleAlpha)
      Q_PROPERTY(bool animation READ animationEnabled WRITE setAnimationEnabled)

  <span class="keyword">public</span>:
      CompositionRenderer(<span class="type"><a href="qwidget.html">QWidget</a></span> <span class="operator">*</span>parent);

      <span class="type">void</span> paint(<span class="type"><a href="../qtgui/qpainter.html">QPainter</a></span> <span class="operator">*</span>) override;

      <span class="type">void</span> setCirclePos(<span class="keyword">const</span> <span class="type"><a href="../qtcore/qpointf.html">QPointF</a></span> <span class="operator">&amp;</span>pos);

      <span class="type"><a href="../qtcore/qsize.html">QSize</a></span> sizeHint() <span class="keyword">const</span> override { <span class="keyword">return</span> <span class="type"><a href="../qtcore/qsize.html">QSize</a></span>(<span class="number">500</span><span class="operator">,</span> <span class="number">400</span>); }

      bool animationEnabled() <span class="keyword">const</span> { <span class="keyword">return</span> m_animation_enabled; }
      <span class="type">int</span> circleColor() <span class="keyword">const</span> { <span class="keyword">return</span> m_circle_hue; }
      <span class="type">int</span> circleAlpha() <span class="keyword">const</span> { <span class="keyword">return</span> m_circle_alpha; }

  <span class="keyword">protected</span>:
      <span class="type">void</span> mousePressEvent(<span class="type"><a href="../qtgui/qmouseevent.html">QMouseEvent</a></span> <span class="operator">*</span>) override;
      <span class="type">void</span> mouseMoveEvent(<span class="type"><a href="../qtgui/qmouseevent.html">QMouseEvent</a></span> <span class="operator">*</span>) override;
      <span class="type">void</span> mouseReleaseEvent(<span class="type"><a href="../qtgui/qmouseevent.html">QMouseEvent</a></span> <span class="operator">*</span>) override;
      <span class="type">void</span> timerEvent(<span class="type"><a href="../qtcore/qtimerevent.html">QTimerEvent</a></span> <span class="operator">*</span>) override;

  <span class="keyword">public</span> <span class="keyword">slots</span>:
      <span class="type">void</span> setClearMode() { m_composition_mode <span class="operator">=</span> <span class="type"><a href="../qtgui/qpainter.html">QPainter</a></span><span class="operator">::</span>CompositionMode_Clear; update(); }
      <span class="type">void</span> setSourceMode() { m_composition_mode <span class="operator">=</span> <span class="type"><a href="../qtgui/qpainter.html">QPainter</a></span><span class="operator">::</span>CompositionMode_Source; update(); }
      <span class="type">void</span> setDestMode() { m_composition_mode <span class="operator">=</span> <span class="type"><a href="../qtgui/qpainter.html">QPainter</a></span><span class="operator">::</span>CompositionMode_Destination; update(); }
      <span class="type">void</span> setSourceOverMode() { m_composition_mode <span class="operator">=</span> <span class="type"><a href="../qtgui/qpainter.html">QPainter</a></span><span class="operator">::</span>CompositionMode_SourceOver; update(); }
      <span class="type">void</span> setDestOverMode() { m_composition_mode <span class="operator">=</span> <span class="type"><a href="../qtgui/qpainter.html">QPainter</a></span><span class="operator">::</span>CompositionMode_DestinationOver; update(); }
      <span class="type">void</span> setSourceInMode() { m_composition_mode <span class="operator">=</span> <span class="type"><a href="../qtgui/qpainter.html">QPainter</a></span><span class="operator">::</span>CompositionMode_SourceIn; update(); }
      <span class="type">void</span> setDestInMode() { m_composition_mode <span class="operator">=</span> <span class="type"><a href="../qtgui/qpainter.html">QPainter</a></span><span class="operator">::</span>CompositionMode_DestinationIn; update(); }
      <span class="type">void</span> setSourceOutMode() { m_composition_mode <span class="operator">=</span> <span class="type"><a href="../qtgui/qpainter.html">QPainter</a></span><span class="operator">::</span>CompositionMode_SourceOut; update(); }
      <span class="type">void</span> setDestOutMode() { m_composition_mode <span class="operator">=</span> <span class="type"><a href="../qtgui/qpainter.html">QPainter</a></span><span class="operator">::</span>CompositionMode_DestinationOut; update(); }
      <span class="type">void</span> setSourceAtopMode() { m_composition_mode <span class="operator">=</span> <span class="type"><a href="../qtgui/qpainter.html">QPainter</a></span><span class="operator">::</span>CompositionMode_SourceAtop; update(); }
      <span class="type">void</span> setDestAtopMode() { m_composition_mode <span class="operator">=</span> <span class="type"><a href="../qtgui/qpainter.html">QPainter</a></span><span class="operator">::</span>CompositionMode_DestinationAtop; update(); }
      <span class="type">void</span> setXorMode() { m_composition_mode <span class="operator">=</span> <span class="type"><a href="../qtgui/qpainter.html">QPainter</a></span><span class="operator">::</span>CompositionMode_Xor; update(); }

      <span class="type">void</span> setPlusMode() { m_composition_mode <span class="operator">=</span> <span class="type"><a href="../qtgui/qpainter.html">QPainter</a></span><span class="operator">::</span>CompositionMode_Plus; update(); }
      <span class="type">void</span> setMultiplyMode() { m_composition_mode <span class="operator">=</span> <span class="type"><a href="../qtgui/qpainter.html">QPainter</a></span><span class="operator">::</span>CompositionMode_Multiply; update(); }
      <span class="type">void</span> setScreenMode() { m_composition_mode <span class="operator">=</span> <span class="type"><a href="../qtgui/qpainter.html">QPainter</a></span><span class="operator">::</span>CompositionMode_Screen; update(); }
      <span class="type">void</span> setOverlayMode() { m_composition_mode <span class="operator">=</span> <span class="type"><a href="../qtgui/qpainter.html">QPainter</a></span><span class="operator">::</span>CompositionMode_Overlay; update(); }
      <span class="type">void</span> setDarkenMode() { m_composition_mode <span class="operator">=</span> <span class="type"><a href="../qtgui/qpainter.html">QPainter</a></span><span class="operator">::</span>CompositionMode_Darken; update(); }
      <span class="type">void</span> setLightenMode() { m_composition_mode <span class="operator">=</span> <span class="type"><a href="../qtgui/qpainter.html">QPainter</a></span><span class="operator">::</span>CompositionMode_Lighten; update(); }
      <span class="type">void</span> setColorDodgeMode() { m_composition_mode <span class="operator">=</span> <span class="type"><a href="../qtgui/qpainter.html">QPainter</a></span><span class="operator">::</span>CompositionMode_ColorDodge; update(); }
      <span class="type">void</span> setColorBurnMode() { m_composition_mode <span class="operator">=</span> <span class="type"><a href="../qtgui/qpainter.html">QPainter</a></span><span class="operator">::</span>CompositionMode_ColorBurn; update(); }
      <span class="type">void</span> setHardLightMode() { m_composition_mode <span class="operator">=</span> <span class="type"><a href="../qtgui/qpainter.html">QPainter</a></span><span class="operator">::</span>CompositionMode_HardLight; update(); }
      <span class="type">void</span> setSoftLightMode() { m_composition_mode <span class="operator">=</span> <span class="type"><a href="../qtgui/qpainter.html">QPainter</a></span><span class="operator">::</span>CompositionMode_SoftLight; update(); }
      <span class="type">void</span> setDifferenceMode() { m_composition_mode <span class="operator">=</span> <span class="type"><a href="../qtgui/qpainter.html">QPainter</a></span><span class="operator">::</span>CompositionMode_Difference; update(); }
      <span class="type">void</span> setExclusionMode() { m_composition_mode <span class="operator">=</span> <span class="type"><a href="../qtgui/qpainter.html">QPainter</a></span><span class="operator">::</span>CompositionMode_Exclusion; update(); }

      <span class="type">void</span> setCircleAlpha(<span class="type">int</span> alpha) { m_circle_alpha <span class="operator">=</span> alpha; update(); }
      <span class="type">void</span> setCircleColor(<span class="type">int</span> hue) { m_circle_hue <span class="operator">=</span> hue; update(); }
      <span class="type">void</span> setAnimationEnabled(bool enabled);

  <span class="keyword">private</span>:
      <span class="type">void</span> updateCirclePos();
      <span class="type">void</span> drawBase(<span class="type"><a href="../qtgui/qpainter.html">QPainter</a></span> <span class="operator">&amp;</span>p);
      <span class="type">void</span> drawSource(<span class="type"><a href="../qtgui/qpainter.html">QPainter</a></span> <span class="operator">&amp;</span>p);

      <span class="type"><a href="../qtgui/qpainter.html">QPainter</a></span><span class="operator">::</span>CompositionMode m_composition_mode;

      <span class="type"><a href="../qtgui/qimage.html">QImage</a></span> m_image;
      <span class="type"><a href="../qtgui/qimage.html">QImage</a></span> m_buffer;
      <span class="type"><a href="../qtgui/qimage.html">QImage</a></span> m_base_buffer;

      <span class="type">int</span> m_circle_alpha;
      <span class="type">int</span> m_circle_hue;

      <span class="type"><a href="../qtcore/qpointf.html">QPointF</a></span> m_circle_pos;
      <span class="type"><a href="../qtcore/qpointf.html">QPointF</a></span> m_offset;

      ObjectType m_current_object;
      bool m_animation_enabled;
      <span class="type">int</span> m_animationTimer;

  <span class="preprocessor">#if QT_CONFIG(opengl)</span>
      <span class="type"><a href="../qtcore/qscopedpointer.html">QScopedPointer</a></span><span class="operator">&lt;</span><span class="type">QFboPaintDevice</span><span class="operator">&gt;</span> m_fbo;
      <span class="type">int</span> m_pbuffer_size; <span class="comment">// width==height==size of pbuffer</span>
      <span class="type"><a href="../qtcore/qtglobal.html#uint-typedef">uint</a></span> m_base_tex;
      <span class="type"><a href="../qtcore/qtglobal.html#uint-typedef">uint</a></span> m_compositing_tex;
      <span class="type"><a href="../qtcore/qsize.html">QSize</a></span> m_previous_size;
      <span class="type"><a href="../qtgui/qopengltextureblitter.html">QOpenGLTextureBlitter</a></span> m_blitter;
  <span class="preprocessor">#endif</span>
  };

  <span class="preprocessor">#endif // COMPOSITION_H</span>

</pre>
</div>
<!-- @@@painting/composition/composition.h -->
        </div>
       </div>
   </div>
   </div>
</div>
<div class="footer">
   <p>
   <acronym title="Copyright">&copy;</acronym> 2019 The Qt Company Ltd.
   Documentation contributions included herein are the copyrights of
   their respective owners.<br/>    The documentation provided herein is licensed under the terms of the    <a href="http://www.gnu.org/licenses/fdl.html">GNU Free Documentation    License version 1.3</a> as published by the Free Software Foundation.<br/>    Qt and respective logos are trademarks of The Qt Company Ltd.     in Finland and/or other countries worldwide. All other trademarks are property
   of their respective owners. </p>
</div>
</body>
</html>
